package com.googlecode.linkmein.domain;

import ymsg.network.Session;
import ymsg.network.YahooUser;

import java.util.ArrayList;

public class Employee {
    private Name name;
    public static final Employee NULL = new NullEmployee();
    private ArrayList<String> yahooFriends;
    private ArrayList<String> msnFriends;
    private Gossipy gossipy = Gossipy.NULL;
    private Albums albums = new Albums();
    private String yim;
    private String msn;
    private String skype;
    private String blog;
    private String gmail;
    private String cellphone;
    private String role;
    private Project project;
    private MapInfo mapInfo;

    public Employee(Contact contact, Resource resource) {
        this.yim = contact.getYim();
        this.msn = contact.getMSN();
        this.skype = contact.getSkype();
        this.blog = contact.getBlog();
        this.gmail = contact.getGoogleId();
        this.cellphone = contact.getCellphone();
        this.role = resource.getRole();
        this.project = resource.getProject();
        this.name = contact.getName().merge(resource.getName());
    }

    public String toString() {
        return name.toString();
    }

    public String getRole() {
        return role;
    }

    public Project getProject() {
        return project;
    }

    public boolean hasName(Name name) {
        return this.name.equals(name);
    }

    public String getEnglishName() {
        return name.getEnglishName();
    }

    public String getShrinkedEnglishName() {
        return name.getShrinkedEnglishName();
    }

    public String getChineseName() {
        return name.getChineseName();
    }

    public String getYIM() {
        return yim;
    }

    public String getMSN() {
        return msn;
    }

    public String getSkype() {
        return skype;
    }

    public String getBlog() {
        return blog;
    }

    public String getGmail() {
        return gmail;
    }

    public String getCellphone() {
        return cellphone;
    }

    public void setYahooFriends(ArrayList<String> yahooFriends) {
        this.yahooFriends = yahooFriends;
    }

    public void setMsnFriends(ArrayList<String> msnFriends) {
        this.msnFriends = msnFriends;
    }

    public ArrayList<String> getYahooFriends() {
        return yahooFriends;
    }

    public Name getName() {
        return name;
    }

    public void setGossipy(Gossipy gossipy) {
        this.gossipy = gossipy;
    }

    public String getConstellation() {
        return gossipy.getBasicAttributes().getConstellation();
    }

    public String getHobbies() {
        return gossipy.getBasicAttributes().getHobbies();
    }

    public String getHatedFood() {
        return gossipy.getPreference().getHatedFood();
    }

    public String getPreferedFood() {
        return gossipy.getPreference().getPreferedFood();
    }

    public String getPreferedDrink() {
        return gossipy.getPreference().getPreferedDrink();
    }

    public String getPreferedMusics() {
        return gossipy.getPreference().getPreferedMusics();
    }

    public String getPreferedVedios() {
        return gossipy.getPreference().getPreferedVedios();
    }

    public String getScared() {
        return gossipy.getBasicAttributes().getScared();
    }

    public String getIdol() {
        return gossipy.getBasicAttributes().getIdol();
    }

    public String getEmbarrassing() {
        return gossipy.getEmbarrassing();
    }

    public String getComment() {
        return gossipy.comment();
    }

    public String getGoogleId() {
        return gmail == null ? "" : gmail.replaceAll("@.*", "");
    }

    public void addAlbum(Album album) {
        albums.add(album);
    }

    public Albums getAlbums() {
        return this.albums;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Employee employee = (Employee) o;

        if (name != null ? !name.equals(employee.name) : employee.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (yahooFriends != null ? yahooFriends.hashCode() : 0);
        result = 31 * result + (msnFriends != null ? msnFriends.hashCode() : 0);
        result = 31 * result + (gossipy != null ? gossipy.hashCode() : 0);
        result = 31 * result + (albums != null ? albums.hashCode() : 0);
        result = 31 * result + (yim != null ? yim.hashCode() : 0);
        result = 31 * result + (msn != null ? msn.hashCode() : 0);
        result = 31 * result + (skype != null ? skype.hashCode() : 0);
        result = 31 * result + (blog != null ? blog.hashCode() : 0);
        result = 31 * result + (gmail != null ? gmail.hashCode() : 0);
        result = 31 * result + (role != null ? role.hashCode() : 0);
        result = 31 * result + (project != null ? project.hashCode() : 0);
        return result;
    }

    public void setMsn(String msn) {
        this.msn = msn;
    }

    public void setYim(String yim) {
        this.yim = yim;
    }

    public void setAlbum(Albums albums) {
        this.albums = albums;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    public MapInfo getMapInfo() {
        return mapInfo;
    }

    public void setMapInfo(MapInfo mapInfo) {
        this.mapInfo = mapInfo;
    }

    public boolean isFriend(Session session) {
        YahooUser user = session.getUser(yim);
        if (user != null) {
            return user.isFriend();
        }
        return false;
    }
}
